/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models;

import classes.Password;
import java.io.IOException;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Achie
 */
@Entity
@Table(name = "Member")
public class User implements Serializable {

    @Id
    @GeneratedValue
    @Column(name = "id")
    private long member_id;
    @Column(name = "email", unique=true, nullable=false)
    private String email;
    @Column(name = "password")
    private String password;
    @Column(name = "joined_on")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date date;
    @Column(name = "firstname")
    private String firstname;
    @Column(name = "insertion")
    private String insertion;
    @Column(name = "lastname")
    private String lastname;

    public User() {
    }

    public User(long member_id, String email, String password, String firstname, String insertion, String lastname) {
        this.setMember_id(member_id);
        this.setEmail(email);
        this.setFirstname(firstname);
        this.setInsertion(insertion);
        this.setLastname(lastname);
        
        try {
            this.setPassword(password);
        } catch (Exception e) {
            System.out.println("Error making password: " + e);
        }
    }

    public long getMember_id() {
        return member_id;
    }

    public void setMember_id(long member_id) {
        this.member_id = member_id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        Password pass = new Password(password);
        String passwordHashed = pass.getHashedPassword();
        this.password = passwordHashed;
    }

    /**
     * @return the date
     */
    public Date getDate() {
        return date;
    }

    /**
     * @param date the date to set
     */
    public void setDate() {
        Date date = new Date();
        this.date = date;
    }

    /**
     * @return the firstname
     */
    public String getFirstname() {
        return firstname;
    }

    /**
     * @param firstname the firstname to set
     */
    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    /**
     * @return the insertion
     */
    public String getInsertion() {
        return insertion;
    }

    /**
     * @param insertion the insertion to set
     */
    public void setInsertion(String insertion) {
        this.insertion = insertion;
    }

    /**
     * @return the lastname
     */
    public String getLastname() {
        return lastname;
    }

    /**
     * @param lastname the lastname to set
     */
    public void setLastname(String lastname) {
        this.lastname = lastname;
    }
}
